/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * manualEntryDialog.java
 *
 * Created on Mar 30, 2011, 11:51:14 AM
 */
package homebudget;

import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Krit
 */
class Produkt{
    String nazwa;
    double ilosc;
    double koszt;
    String nazwaSklepu;
    String kategoria;

    public String getKategoria() {
        return kategoria;
    }

    public void setKategoria(String kategoria) {
        this.kategoria = kategoria;
    }
    public String getNazwaSklepu() {
        return nazwaSklepu;
    }
    public void setNazwaSklepu(String nazwaSklepu) {
        this.nazwaSklepu = nazwaSklepu;
    }
    public double getIlosc() {
        return ilosc;
    }
    public void setIlosc(double ilosc) {
        this.ilosc = ilosc;
    }
    public double getKoszt() {
        return koszt;
    }
    public void setKoszt(double koszt) {
        this.koszt = koszt;
    }
    public String getNazwa() {
        return nazwa;
    }
    public void setNazwa(String nazwa) {
        this.nazwa = nazwa;
    }

}

class TableModelProdukt extends AbstractTableModel{

    LinkedList<Produkt> lista;
    public TableModelProdukt(){
        lista = new LinkedList<Produkt>();
    }

    public void dodajProdukt(String nazwa,double ilosc,double koszt,String nazwaSklepu,String kategoria){
        Produkt nowy = new Produkt();
        nowy.nazwa = nazwa;
        nowy.ilosc = ilosc;
        nowy.koszt = koszt;
        nowy.nazwaSklepu = nazwaSklepu;
        nowy.kategoria = kategoria;

        lista.add(nowy);
        this.fireTableStructureChanged();

    }

    public void removeRow(int row){
        lista.remove(row);
        this.fireTableStructureChanged();
    }

    public int getRowCount() {
        return lista.size();
    }

    public int getColumnCount() {
        return 5;
    }

    @Override
    public String getColumnName(int column) {
        if(column==0){
            return "Nazwa";
        }
        if(column==1){
            return "Ilosc";
        }
        if(column==2){
            return "Koszt";
        }
        if(column==3){
            return "Nazwa sklepu";
        }
        if(column==4){
            return "Kategoria";
        }
        return "";
    }



    public Object getValueAt(int rowIndex, int columnIndex) {
        Produkt produkt = lista.get(rowIndex);
        Object tmp=new Object();
        switch(columnIndex){
            case 0: tmp = (String)produkt.getNazwa();
                    break;
            case 1: tmp = (Double)produkt.getIlosc();
                    break;
            case 2: tmp = (Double)produkt.getKoszt();
                    break;
            case 3: tmp = (String)produkt.getNazwaSklepu();
                    break;
            case 4: tmp = (String)produkt.getKategoria();
                    break;
        }
        return tmp;
    }
}

public class manualEntryDialog extends javax.swing.JDialog {

    public boolean isCanceled = true;
    public DataBase db = null;
    java.awt.Frame rodzic;
    TableModelProdukt model;


    /** Creates new form manualEntryDialog */
    public manualEntryDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        rodzic = parent;
        
        initComponents();


        chooseModeCombo.setSelectedIndex(0);
        jPanelDodajProdukt.setVisible(false);


        
        jPanelWydatek.setVisible(false);
        jPanelTabela.setVisible(false);
        jPanelWplata.setVisible(false);
    }

    public void setDataBase(DataBase newdb) {
        this.db = newdb;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel7 = new javax.swing.JLabel();
        chooseModeCombo = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jComboBoxKategoria = new javax.swing.JComboBox();
        addEntryButton = new javax.swing.JButton();
        jPanelWydatek = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldNazwaWydatku = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldDataWydatku = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldWartoscWydatku = new javax.swing.JTextField();
        jButtonOtworzPanelDodawania = new javax.swing.JButton();
        jPanelDodajProdukt = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNazwaProduktu = new javax.swing.JTextField();
        jTextFieldIloscProduktu = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldKosztProduktu = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jComboBoxSklep = new javax.swing.JComboBox();
        jButtonDodajNowySklep = new javax.swing.JButton();
        jButtonDodajProdukt = new javax.swing.JButton();
        jButtonUsunZaznaczony = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jComboBoxKategoriaProduktu = new javax.swing.JComboBox();
        jPanelTabela = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableProdukty = new javax.swing.JTable();
        jPanelWplata = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldNazwaWplaty = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextFieldDataWplaty = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldWartoscWplaty = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(homebudget.HomeBudgetApp.class).getContext().getResourceMap(manualEntryDialog.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        chooseModeCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "","Wydatek", "Wplata" }));
        chooseModeCombo.setName("chooseModeCombo"); // NOI18N
        chooseModeCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chooseModeComboItemStateChanged(evt);
            }
        });
        chooseModeCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseModeComboActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jComboBoxKategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "" }));
        jComboBoxKategoria.setName("jComboBoxKategoria"); // NOI18N

        addEntryButton.setText(resourceMap.getString("addEntryButton.text")); // NOI18N
        addEntryButton.setName("addEntryButton"); // NOI18N
        addEntryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addEntryButtonActionPerformed(evt);
            }
        });

        jPanelWydatek.setName("jPanelWydatek"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldNazwaWydatku.setText(resourceMap.getString("jTextFieldNazwaWydatku.text")); // NOI18N
        jTextFieldNazwaWydatku.setName("jTextFieldNazwaWydatku"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldDataWydatku.setText(resourceMap.getString("jTextFieldDataWydatku.text")); // NOI18N
        jTextFieldDataWydatku.setName("jTextFieldDataWydatku"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldWartoscWydatku.setText(resourceMap.getString("jTextFieldWartoscWydatku.text")); // NOI18N
        jTextFieldWartoscWydatku.setName("jTextFieldWartoscWydatku"); // NOI18N

        jButtonOtworzPanelDodawania.setText(resourceMap.getString("jButtonOtworzPanelDodawania.text")); // NOI18N
        jButtonOtworzPanelDodawania.setName("jButtonOtworzPanelDodawania"); // NOI18N
        jButtonOtworzPanelDodawania.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOtworzPanelDodawaniaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelWydatekLayout = new javax.swing.GroupLayout(jPanelWydatek);
        jPanelWydatek.setLayout(jPanelWydatekLayout);
        jPanelWydatekLayout.setHorizontalGroup(
            jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWydatekLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelWydatekLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldNazwaWydatku, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))
                    .addGroup(jPanelWydatekLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldDataWydatku, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
                    .addGroup(jPanelWydatekLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldWartoscWydatku, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                    .addComponent(jButtonOtworzPanelDodawania))
                .addContainerGap())
        );
        jPanelWydatekLayout.setVerticalGroup(
            jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWydatekLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldNazwaWydatku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldDataWydatku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelWydatekLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldWartoscWydatku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addComponent(jButtonOtworzPanelDodawania))
        );

        jPanelDodajProdukt.setName("jPanelDodajProdukt"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldNazwaProduktu.setText(resourceMap.getString("jTextFieldNazwaProduktu.text")); // NOI18N
        jTextFieldNazwaProduktu.setName("jTextFieldNazwaProduktu"); // NOI18N
        jTextFieldNazwaProduktu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNazwaProduktuActionPerformed(evt);
            }
        });
        jTextFieldNazwaProduktu.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTextFieldNazwaProduktuPropertyChange(evt);
            }
        });

        jTextFieldIloscProduktu.setText(resourceMap.getString("jTextFieldIloscProduktu.text")); // NOI18N
        jTextFieldIloscProduktu.setName("jTextFieldIloscProduktu"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jTextFieldKosztProduktu.setText(resourceMap.getString("jTextFieldKosztProduktu.text")); // NOI18N
        jTextFieldKosztProduktu.setName("jTextFieldKosztProduktu"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jComboBoxSklep.setName("jComboBoxSklep"); // NOI18N

        jButtonDodajNowySklep.setText(resourceMap.getString("jButtonDodajNowySklep.text")); // NOI18N
        jButtonDodajNowySklep.setName("jButtonDodajNowySklep"); // NOI18N
        jButtonDodajNowySklep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDodajNowySklepActionPerformed(evt);
            }
        });

        jButtonDodajProdukt.setText(resourceMap.getString("jButtonDodajProdukt.text")); // NOI18N
        jButtonDodajProdukt.setName("jButtonDodajProdukt"); // NOI18N
        jButtonDodajProdukt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDodajProduktActionPerformed(evt);
            }
        });

        jButtonUsunZaznaczony.setText(resourceMap.getString("jButtonUsunZaznaczony.text")); // NOI18N
        jButtonUsunZaznaczony.setName("jButtonUsunZaznaczony"); // NOI18N
        jButtonUsunZaznaczony.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUsunZaznaczonyActionPerformed(evt);
            }
        });

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jComboBoxKategoriaProduktu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "" }));
        jComboBoxKategoriaProduktu.setName("jComboBoxKategoriaProduktu"); // NOI18N
        jComboBoxKategoriaProduktu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxKategoriaProduktuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDodajProduktLayout = new javax.swing.GroupLayout(jPanelDodajProdukt);
        jPanelDodajProdukt.setLayout(jPanelDodajProduktLayout);
        jPanelDodajProduktLayout.setHorizontalGroup(
            jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                        .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldKosztProduktu)
                            .addComponent(jTextFieldIloscProduktu)
                            .addComponent(jTextFieldNazwaProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                        .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel10))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxKategoriaProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                                .addComponent(jButtonDodajProdukt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonUsunZaznaczony))
                            .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                                .addComponent(jComboBoxSklep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonDodajNowySklep)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDodajProduktLayout.setVerticalGroup(
            jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDodajProduktLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNazwaProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldIloscProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldKosztProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jComboBoxSklep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonDodajNowySklep))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jComboBoxKategoriaProduktu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(jPanelDodajProduktLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonDodajProdukt)
                    .addComponent(jButtonUsunZaznaczony)))
        );

        jPanelTabela.setName("jPanelTabela"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTableProdukty.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1"
            }
        ));
        jTableProdukty.setColumnSelectionAllowed(true);
        jTableProdukty.setName("jTableProdukty"); // NOI18N
        jTableProdukty.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableProduktyMouseClicked(evt);
            }
        });
        jTableProdukty.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTableProduktyPropertyChange(evt);
            }
        });
        jScrollPane1.setViewportView(jTableProdukty);
        jTableProdukty.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        javax.swing.GroupLayout jPanelTabelaLayout = new javax.swing.GroupLayout(jPanelTabela);
        jPanelTabela.setLayout(jPanelTabelaLayout);
        jPanelTabelaLayout.setHorizontalGroup(
            jPanelTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTabelaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelTabelaLayout.setVerticalGroup(
            jPanelTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTabelaLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanelWplata.setName("jPanelWplata"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jTextFieldNazwaWplaty.setText(resourceMap.getString("jTextFieldNazwaWplaty.text")); // NOI18N
        jTextFieldNazwaWplaty.setName("jTextFieldNazwaWplaty"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jTextFieldDataWplaty.setText(resourceMap.getString("jTextFieldDataWplaty.text")); // NOI18N
        jTextFieldDataWplaty.setName("jTextFieldDataWplaty"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jTextFieldWartoscWplaty.setText(resourceMap.getString("jTextFieldWartoscWplaty.text")); // NOI18N
        jTextFieldWartoscWplaty.setName("jTextFieldWartoscWplaty"); // NOI18N

        javax.swing.GroupLayout jPanelWplataLayout = new javax.swing.GroupLayout(jPanelWplata);
        jPanelWplata.setLayout(jPanelWplataLayout);
        jPanelWplataLayout.setHorizontalGroup(
            jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWplataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldWartoscWplaty)
                    .addComponent(jTextFieldDataWplaty)
                    .addComponent(jTextFieldNazwaWplaty, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                .addContainerGap(310, Short.MAX_VALUE))
        );
        jPanelWplataLayout.setVerticalGroup(
            jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelWplataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldNazwaWplaty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldDataWplaty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelWplataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldWartoscWplaty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelTabela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chooseModeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9))
                            .addComponent(jPanelWydatek, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jComboBoxKategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(addEntryButton))
                            .addComponent(jPanelDodajProdukt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(86, 86, 86))))
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jPanelWplata, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(chooseModeCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jComboBoxKategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addEntryButton))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelWydatek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelDodajProdukt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelTabela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelWplata, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addEntryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEntryButtonActionPerformed
        isCanceled = false;    
        String wartosc = "";
        String data = "";
        if(chooseModeCombo.getSelectedIndex()==2){
             wartosc = jTextFieldWartoscWplaty.getText();
             data = jTextFieldDataWplaty.getText();
        }else if(chooseModeCombo.getSelectedIndex()==1){
            wartosc = jTextFieldWartoscWydatku.getText();
            data = jTextFieldDataWydatku.getText();
        }

        if(!wartosc.equals("") && !data.equals("")){
        //sprawdzanie wartosc
        Pattern pattern = Pattern.compile("^[0-9]+\\.?[0-9]*$");
        Matcher matcher = pattern.matcher(wartosc);

        //sprawdzenie daty        
        Pattern pattern2 = Pattern.compile("^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$");
        Matcher matcher2= pattern2.matcher(data);

        if(!matcher.find()){
            JOptionPane.showMessageDialog(rootPane, "Nie prawidłowy format w polu \"wartosc\". ","Bład",JOptionPane.ERROR_MESSAGE);
        }else
            if(!matcher2.find()){
                JOptionPane.showMessageDialog(rootPane, "Nie prawidłowy format w polu \"Data\". ","Bład",JOptionPane.ERROR_MESSAGE);

        }else{

        switch (chooseModeCombo.getSelectedIndex()) {
            case 1:
                DataBaseMySql baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
                String nazwaWydatku = jTextFieldNazwaWydatku.getText();
                String dataWydatku = jTextFieldDataWydatku.getText();
                String wartoscWydatku = jTextFieldWartoscWydatku.getText();
                String nazwaKategorii = (String)jComboBoxKategoria.getSelectedItem();
                //pobieranie idKategorii
                int idKategorii = baza.idKatWydatek(nazwaKategorii);

                int idWydatku = baza.dodajWydatek(nazwaWydatku,idKategorii,Double.parseDouble(wartoscWydatku),dataWydatku);
                baza.dodajBudzetWydatek(HomeBudgetApp.getIdbudzetu(), idWydatku);
                int idProdukt;
                int idSklep;
                int idKategoriiProduktu;
                double cena;
                Produkt tymczasowy = new Produkt();

                
                
                if(jTableProdukty.getModel() instanceof TableModelProdukt){
                    TableModelProdukt model = (TableModelProdukt) jTableProdukty.getModel();
                for(int i=0;i<model.lista.size();i++){
                    tymczasowy = model.lista.get(i);

                    idSklep = baza.idSklep(tymczasowy.getNazwaSklepu());
                    idKategoriiProduktu = baza.idKatProdukt(tymczasowy.getKategoria());
                    cena = tymczasowy.getKoszt() / tymczasowy.getIlosc();
                    idProdukt = baza.dodajProdukt(tymczasowy.getNazwa(),idSklep,idKategoriiProduktu,cena,HomeBudgetApp.getIdbudzetu());

                    baza.dodajProduktDoWydatku(idWydatku, idProdukt,tymczasowy.getIlosc() ,tymczasowy.getKoszt());
                }

                }else
                {
                    baza.dodajProduktDoWydatku(idWydatku,1,0, 0);
                }
                baza.close();
                JOptionPane.showMessageDialog(rootPane, "Dodano wpis do bazy ","Sukces",JOptionPane.INFORMATION_MESSAGE);


                break;
            case 2:
                baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
                String nazwaWplaty = jTextFieldNazwaWplaty.getText();
                String dataWplaty = jTextFieldDataWplaty.getText();
                String wartoscWplaty = jTextFieldWartoscWplaty.getText();
                String nazwaKategorii2 = (String)jComboBoxKategoria.getSelectedItem();

                idKategorii = baza.idKatPrzychod(nazwaKategorii2);

                int idPrzychod = baza.dodajPrzychod(nazwaWplaty, idKategorii, Double.parseDouble(wartoscWplaty), dataWplaty);
                baza.dodajBudzetPrzychod(HomeBudgetApp.getIdbudzetu(), idPrzychod);
                 JOptionPane.showMessageDialog(rootPane, "Dodano wpis do bazy ","Sukces",JOptionPane.INFORMATION_MESSAGE);
                break;
        }
        }
      //  JOptionPane.showMessageDialog(rootPane, "Dodano wpis do bazy ","Sukces",JOptionPane.INFORMATION_MESSAGE);
        //dispose();
        }
    }//GEN-LAST:event_addEntryButtonActionPerformed

    private void chooseModeComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chooseModeComboItemStateChanged
        DataBaseMySql baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        LinkedList<String> lista;
        switch (chooseModeCombo.getSelectedIndex()) {
            case 0:
                System.out.println("ff");
                break;
            case 1:
                lista = baza.listaKategoriaWydatek();
                jComboBoxKategoria.setModel(new DefaultComboBoxModel(lista.toArray()));
                jPanelWydatek.setVisible(true);
                jPanelWplata.setVisible(false);
                break;
            case 2:
                lista = baza.listaKategoriaPrzychod();
                jComboBoxKategoria.setModel(new DefaultComboBoxModel(lista.toArray()));
                jPanelWydatek.setVisible(false);
                jPanelTabela.setVisible(false);
                jPanelDodajProdukt.setVisible(false);

                jPanelWplata.setVisible(true);
                break;
            default:
                break;
        }
        baza.close();
    }//GEN-LAST:event_chooseModeComboItemStateChanged

    private void jButtonDodajNowySklepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDodajNowySklepActionPerformed
        // TODO add your handling code here:
        ShopsDialog dialog = new ShopsDialog(rodzic, true);
        dialog.setVisible(true);
        DataBaseMySql baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        
        jComboBoxSklep.setModel((new DefaultComboBoxModel(baza.listaSklep().toArray())));
        baza.close();
    }//GEN-LAST:event_jButtonDodajNowySklepActionPerformed

    private void jButtonDodajProduktActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDodajProduktActionPerformed
        // TODO add your handling code here:

       
        String nazwaProduktu = jTextFieldNazwaProduktu.getText();
        String ilosc = jTextFieldIloscProduktu.getText();
        String koszt = jTextFieldKosztProduktu.getText();
        String nazwaSklepu = (String)jComboBoxSklep.getSelectedItem();
        String kategoria = (String)jComboBoxKategoriaProduktu.getSelectedItem();

        //waliacja
        Pattern pattern = Pattern.compile("^[0-9]+\\.?[0-9]*$");
        Matcher matcher = pattern.matcher(ilosc);
        Matcher matcher2 = pattern.matcher(koszt);

        
        if(!matcher.find()){
            JOptionPane.showMessageDialog(rootPane, "Nie prawidłowy format w polu \"ilosc\". ","Bład",JOptionPane.ERROR_MESSAGE);

        }
        else if(!matcher2.find()){
            JOptionPane.showMessageDialog(rootPane, "Nie prawidłowy format w polu \"koszt\". ","Błąd",JOptionPane.ERROR_MESSAGE);
        }else{
            //dodawnie produktu do listy
            model = (TableModelProdukt) jTableProdukty.getModel();
            model.dodajProdukt(nazwaProduktu, Double.parseDouble(ilosc), Double.parseDouble(koszt), nazwaSklepu,kategoria);
            TableModelProdukt tmp = new TableModelProdukt();
            tmp.lista = model.lista;
            jTableProdukty.setModel(tmp);
            
        }
      //  TableModelProdukt tmp = new TableModelProdukt();
     //   tmp.lista = mod.lista;
       
       
    }//GEN-LAST:event_jButtonDodajProduktActionPerformed

    private void jButtonOtworzPanelDodawaniaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOtworzPanelDodawaniaActionPerformed
        // TODO add your handling code here:
        model = new TableModelProdukt();

        jTableProdukty.setModel(model);        
        jPanelDodajProdukt.setVisible(true);
        jPanelTabela.setVisible(true);

        DataBaseMySql baza = new DataBaseMySql(HomeBudgetApp.getConnectionString());
        jComboBoxSklep.setModel(new DefaultComboBoxModel(baza.listaSklep().toArray()));
        jComboBoxKategoriaProduktu.setModel(new DefaultComboBoxModel(baza.listaKategoriaProdukt().toArray()));

        baza.close();
        jButtonUsunZaznaczony.setVisible(false);
    }//GEN-LAST:event_jButtonOtworzPanelDodawaniaActionPerformed

    private void jButtonUsunZaznaczonyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUsunZaznaczonyActionPerformed
        // TODO add your handling code here:
        int row = jTableProdukty.getSelectedRow();
        model = (TableModelProdukt) jTableProdukty.getModel();
        model.removeRow(row);
        if(model.lista.size()<=0)
            jButtonUsunZaznaczony.setVisible(false);
        jTableProdukty.setModel(model);
    }//GEN-LAST:event_jButtonUsunZaznaczonyActionPerformed

    private void jTableProduktyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableProduktyMouseClicked
        // TODO add your handling code here:
        jButtonUsunZaznaczony.setVisible(true);
    }//GEN-LAST:event_jTableProduktyMouseClicked

    private void jTableProduktyPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTableProduktyPropertyChange
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jTableProduktyPropertyChange

    private void jTextFieldNazwaProduktuPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTextFieldNazwaProduktuPropertyChange
        // TODO add your handling code here:
       
    }//GEN-LAST:event_jTextFieldNazwaProduktuPropertyChange

    private void jTextFieldNazwaProduktuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNazwaProduktuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNazwaProduktuActionPerformed

    private void chooseModeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseModeComboActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_chooseModeComboActionPerformed

    private void jComboBoxKategoriaProduktuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxKategoriaProduktuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxKategoriaProduktuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                manualEntryDialog dialog = new manualEntryDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(
                        true);
            }
        });


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addEntryButton;
    private javax.swing.JComboBox chooseModeCombo;
    private javax.swing.JButton jButtonDodajNowySklep;
    private javax.swing.JButton jButtonDodajProdukt;
    private javax.swing.JButton jButtonOtworzPanelDodawania;
    private javax.swing.JButton jButtonUsunZaznaczony;
    private javax.swing.JComboBox jComboBoxKategoria;
    private javax.swing.JComboBox jComboBoxKategoriaProduktu;
    private javax.swing.JComboBox jComboBoxSklep;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanelDodajProdukt;
    private javax.swing.JPanel jPanelTabela;
    private javax.swing.JPanel jPanelWplata;
    private javax.swing.JPanel jPanelWydatek;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableProdukty;
    private javax.swing.JTextField jTextFieldDataWplaty;
    private javax.swing.JTextField jTextFieldDataWydatku;
    private javax.swing.JTextField jTextFieldIloscProduktu;
    private javax.swing.JTextField jTextFieldKosztProduktu;
    private javax.swing.JTextField jTextFieldNazwaProduktu;
    private javax.swing.JTextField jTextFieldNazwaWplaty;
    private javax.swing.JTextField jTextFieldNazwaWydatku;
    private javax.swing.JTextField jTextFieldWartoscWplaty;
    private javax.swing.JTextField jTextFieldWartoscWydatku;
    // End of variables declaration//GEN-END:variables
}
